<?php
/**
 * 自动加载类
 * 
 * @desc 自动加载核心类、控制器类、模型类、第三方类库等
 * @author keluo<pycorvn@yeah.net>
 * @since 2015-01-24
 */
class SCAutoloader {
    
    /**
     * 
     * 加载类文件
     * @param string $className
     * @throws Exception
     * @todo 允许用户在config.php中自定义类文件自动加载清单，如：
     * 'autoloads' => array(
     *     'vendor', 'helper', ...
     * )
     */
    public static function loadClass($className) {
        $search_lib_path = array(SC_SYS_CORE_PATH, SC_CONTROLLER_PATH, SC_VENDOR_PATH);
        foreach($search_lib_path as $lib_path) {
            foreach(new DirectoryIterator($lib_path) as $file) {
                if($file->isDot()) continue;
                if($file->isDir()) continue;
                if(0 === strcasecmp($file->getFileName(), $className.'.class.php')) {
                    return require_once $lib_path.'/'.$file->getFileName();
                }    
            }
        }
    }
}